package org.wanho.rent.dao.impl;

import java.util.List;

import org.wanho.jdbc.util.JdbcTemplate;
import org.wanho.jdbc.util.RowMapper;
import org.wanho.rent.constant.Constant;
import org.wanho.rent.dao.ProductTypeDao;
import org.wanho.rent.entity.ProductType;
import org.wanho.rent.factory.ObjectFactory;
import org.wanho.rent.mapper.CountRowMapper;
import org.wanho.rent.mapper.ProductTypeMapper;

public class ProductTypeDaoImpl implements ProductTypeDao {

	private JdbcTemplate<ProductType> jt = (JdbcTemplate<ProductType>) ObjectFactory.getObject("jt");
	private RowMapper<ProductType> rm = new ProductTypeMapper();
	
	@Override
	public List<ProductType> selectByPage(int pageNo, int pageSize) {
		String sql = new StringBuffer()
			.append(" select ")
			.append(" 	producttypeid,producttypename,producttypestate ")
			.append(" from ")
			.append(" 	producttype ")
			.append(" limit ?,? ")
			.toString();
		return jt.query(sql, rm, (pageNo-1)*pageSize, pageSize);
	}

	/**
	 * 查询总条数
	 */
	@Override
	public int selectCount() {
		String sql = new StringBuffer()
			.append(" select ")
			.append(" 	count(*) ")
			.append(" from ")
			.append(" 	producttype ")
			.toString();
		JdbcTemplate<Integer> jt2 = (JdbcTemplate<Integer>) ObjectFactory.getObject("jt");
		return jt2.queryForObject(sql, new CountRowMapper());
	}

	@Override
	public List<ProductType> selectAll() {
		String sql = new StringBuffer()
			.append(" select ")
			.append(" 	producttypeid,producttypename,producttypestate ")
			.append(" from ")
			.append(" 	producttype ")
			.append(" where	 ")
			.append(" 	producttypestate=? ")
			.toString();
		return jt.query(sql, rm, Constant.STATUS_ENABLE);
	}

}
